home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Development Tools & Languages / DTSCPlusLibrary / Sources / Application.h < prev    next >
Encoding:
Text File  |  1993-01-14  |  9.2 KB  |  313 lines  |  [TEXT/MPS ]

  1. /* _________________________________________________________________________________________________________ //
  2.   Copyright Â© 1992-93 Apple Computer, Inc. All rights reserved.
  3.   Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
  4.   Date: 11/6/92
  5.   Revision comments are at the end of this file.
  6.   ---
  7.   TApplication is an abstract base class, TBKApplication is a background only application class,
  8.   TGUIApplication is a window-based user application class. TQTApplication is a QuickTime aware application
  9.   class, TGXApplication is a Quickdraw GX aware application class. Finally TQTAndGXApplication 
  10.   handles both QX and QT application work.
  11.   Application.h contains application level classes for building the wire for an application framework.
  12.   _________________________________________________________________________________________________________ */
  13.  
  14. // Declare label for this header file
  15. #ifndef _APPLICATION_
  16. #define _APPLICATION_
  17.  
  18.  
  19. #ifndef _DTSCPLUSLIBRARY_
  20. #include "DTSCPlusLibrary.h"
  21. #endif
  22.  
  23. //    Toolbox Interfaces
  24. #ifndef __QUICKDRAW__
  25. #include <Quickdraw.h>
  26. #endif
  27.  
  28. #ifndef __EVENTS__
  29. #include <Events.h>
  30. #endif
  31.  
  32. #ifndef __OSEVENTS__
  33. #include <OSEvents.h>
  34. #endif
  35.  
  36. #ifndef __MEMORY__
  37. #include <Memory.h>
  38. #endif
  39.  
  40. #ifndef __WINDOWS__
  41. #include <Windows.h>
  42. #endif
  43.  
  44. #ifndef __DESK__
  45. #include <Desk.h>
  46. #endif
  47.  
  48. #ifndef __FONTS__
  49. #include <Fonts.h>
  50. #endif
  51.  
  52. #ifndef __TOOLUTILS__
  53. #include <ToolUtils.h>
  54. #endif
  55.  
  56. #ifndef __DIALOGS__
  57. #include <Dialogs.h>
  58. #endif
  59.  
  60. #ifndef __MENUS__
  61. #include <Menus.h>
  62. #endif
  63.  
  64. #ifndef __TEXTEDIT__
  65. #include <TextEdit.h>
  66. #endif
  67.  
  68. #ifndef __APPLEEVENTS_
  69. #include <AppleEvents.h>
  70. #endif
  71.  
  72. #ifndef __RESOURCES__
  73. #include <Resources.h>
  74. #endif
  75.  
  76. #ifndef __DISKINIT__
  77. #include <DiskInit.h>
  78. #endif
  79.  
  80. // DTS Library headers
  81. #ifndef _WINDOW_
  82. #include "Window.h"
  83. #endif
  84.  
  85. #ifndef _APPLEEVENT_
  86. #include "AppleEvent.h"
  87. #endif
  88.  
  89. #include "Menu.h"
  90.  
  91.  
  92. #include <AERegistry.h>
  93.  
  94.  
  95. #include "ApplicationResources.h"
  96. #include "CollectionClasses.h"
  97.  
  98. // GLOBAL INTERNAL STRUCTURES
  99.  
  100. struct AEEventTable
  101. {                                                // AppleEvent record
  102.     OSType theClass;
  103.     OSType theID;
  104.     long theValue;
  105. };
  106.  
  107.  
  108. typedef AEEventTable* AEEventTablePtr;
  109.  
  110. // _________________________________________________________________________________________________________ //
  111. //    TApplication Interface.
  112.  
  113. class TApplication
  114. // The TApplication is the base class for Application classes. It contains the basic behavior
  115. // for any application work. Note that it's an abstract class.
  116. {
  117. public:
  118.     // TYPEDEFS AND ENUMS
  119.     enum EConstants
  120.     {
  121.         kForgroundSleepValue = 0, kSuspendResumeMessage = 1, kResumeMask = 1, kHighByte = 24, kBackgroundSleepValue = 60
  122.     };
  123.  
  124.  
  125.     enum EState
  126.     {
  127.         kInit = 1, kRun, kQuit
  128.     };
  129.  
  130.     // CONSTRUCTORS AND DESTRUCTORS
  131.     TApplication();                                // default constructor
  132.     virtual~ TApplication();                    // default destructor
  133.  
  134.     // MAIN INTERFACE
  135.     virtual void InitializeMemory();            // initialize our memory needs
  136.     virtual void InitializeToolbox() = 0;        // initialize the toolbox
  137.  
  138.     // EVENT AND CONTROL METHODS
  139.     virtual void DoNextEvent();                    // handle the incoming events
  140.     virtual void DoEventLoop(){};                // handle the actual event dispatching
  141.     virtual void DoHighLevelEvent();            // handle high level events
  142.  
  143.     virtual void Start();                        // start the application and let it run
  144.     virtual void DoIdle() = 0;                    // call idle handler
  145.     virtual void Quit();                        // quit the application 
  146.     virtual void DoCommand(long     /*command*/){};// handle commands
  147.  
  148.     // CORE AE HANDLER METHODS
  149.     virtual void InstallAEHandler();            // install our AE dispatcher
  150.     virtual void DispatchAppleEvents(AppleEvent* in,
  151.                                      AppleEvent* out,
  152.                                      long Command);// Dispatch incoming Apple Events in the framework
  153.  
  154.     virtual OSErr HandleQuit(AppleEvent* in,
  155.                              AppleEvent* out,
  156.                              long refCon);        // handle the quit AE
  157.     virtual OSErr HandleOpen(AppleEvent* in,
  158.                              AppleEvent* out,
  159.                              long refCon);        // handle the open AE
  160.     virtual OSErr HandleOpenDocuments(AppleEvent* in,
  161.                                       AppleEvent* out,
  162.                                       long refCon);// handle the open document AE
  163.     virtual OSErr HandlePrint(AppleEvent* in,
  164.                               AppleEvent* out,
  165.                               long refCon);        // handle the print command
  166.  
  167.     // STATE CHANGE METHODS
  168.     virtual void SetState(TApplication::EState theState);// change the state of the application FSM
  169.  
  170.     // FIELDS
  171. protected:
  172.     RgnHandle fSleepRegion;                        // our sleep region (for possible mouse movements)
  173.     long fSleepValue;                            // defined sleep value for WaitNextEvent
  174.     EventRecord fEventRecord;                    // current event record
  175.     short fEventMask;                            // our eventMask
  176.     short fMoreMasters;                            // amount of MoreMaster calls
  177.     TAppleEvent fMessenger;                        // our AE posting system
  178.     EState fState;                                // internal state of the TApplication
  179.     OSErr fError;                                // latest error
  180. };
  181.  
  182.  
  183. // _________________________________________________________________________________________________________ //
  184. //    TBKApplication Interface.
  185.  
  186. class TBKApplication : public TApplication
  187. // The TBKApplication is the base class for background only/faceless applications. It provides
  188. // the basic skeleton for building such applications.
  189. {
  190. public:
  191.     // CONSTRUCTORS AND DESTRUCTORS
  192.     TBKApplication();
  193.     virtual~ TBKApplication();
  194. };
  195.  
  196.  
  197. // _________________________________________________________________________________________________________ //
  198. //    TGUIApplication Interface.
  199.  
  200. class TGUIApplication : public TApplication
  201. // The TGUIApplication is the base class for writing window/menu based user interaction applications.
  202. {
  203. public:
  204.     // CONSTRUCTORS AND DESTRUCTORS
  205.     TGUIApplication();                            // default constructor
  206.     virtual~ TGUIApplication();                    // default destructor
  207.  
  208.     // MAIN INTERFACE
  209.     // CONTROL
  210.     virtual void InitializeToolbox();            // initialize the toolbox
  211.     virtual void Start();                        // handle the cursor before calling inherited Start
  212.     virtual void DoEventLoop();                    // handle the actual event dispatching
  213.  
  214.     // SYSTEM
  215.     virtual void DoIdle();                        // handle idle time
  216.     virtual void DoSystemTime();                // handle DA time
  217.     virtual void DoDiskEvent();                    // handle disk insertion events
  218.     virtual void DispatchAppleEvents(AppleEvent* in,
  219.                                      AppleEvent* out,
  220.                                      long command);
  221.  
  222.     // GENERAL WINDOW EVENTS
  223.     virtual void DoWindowUpdate();                // handle window updating
  224.     virtual void DoDragWindow();                // handle inDrag events
  225.     virtual void DoGoAwayWindow();                // handle doGoAway events
  226.     virtual void DoInWindowContent();            // handle window mouse clicks
  227.  
  228.     // MENU EVENTS
  229.     virtual void DoMenuCommand();                // handle menu command
  230.     virtual void DoInternalMenus(long command);    // handle internal menus (Apple)
  231.     virtual void DoCommand(long command);        // handle commands related to default GUI
  232.     virtual long CalculateMenuCommand(long menuentry);// calculate the menu command
  233.  
  234.     // AE HANDLING
  235.     virtual OSErr HandleOpen(AppleEvent* in,
  236.                              AppleEvent* out,
  237.                              long refCon);        // OVERRIDE - handle the open AE
  238.  
  239.     // DOCUMENT METHODS
  240.     virtual void DoCreateDocument();            // create our document (default one window)
  241.     virtual void DoCreateDocument(short windowID);// create our document from a resource (default one window)
  242.     virtual void AddDocument(TWindow* theDocument);// add the document to the list of known ones
  243.  
  244.     // USER INTERACTIONS
  245.     virtual void Draw();                        // draw in the main window
  246.     virtual void DoClick();                        // handle a click inside a window
  247.     virtual void AdjustUserInterface(){};        // adjust the user interface based on state changes
  248.     virtual void DoAboutBox();                    // present our About… box
  249.     virtual void DoHelp();                        // a hook to a possible outside help system
  250.  
  251.     // FIELDS
  252. protected:
  253.     CursHandle fCursHandle;                        // current cursor selected
  254.     TWindow* fDocument;                            // our only window/document (create list of windows later)
  255.     WindowPtr fCurrentWindow;                    // the current window attached to the event
  256.     short fWindowNum;                            // amount of windows
  257.     long fMenuResult;                            // value received from menu
  258. };
  259.  
  260.  
  261. // _________________________________________________________________________________________________________ //
  262. //    TQTApplication Interface.
  263.  
  264. class TQTApplication : public TGUIApplication
  265. // The TQTApplication is the base class for writing window/menu based user interaction applications
  266. // that also handles QuickTime calls.
  267. {
  268. public:
  269.     // CONSTRUCTORS AND DESTRUCTORS
  270.     TQTApplication();
  271.     virtual~ TQTApplication();
  272. };
  273.  
  274.  
  275. // _________________________________________________________________________________________________________ //
  276. //    TGXApplication Interface.
  277.  
  278. class TGXApplication : public TGUIApplication
  279. // The TGXApplication is the base class for writing window/menu based user interaction applications
  280. // that also handles Quickdraw GX calls.
  281. {
  282. public:
  283.     // CONSTRUCTORS AND DESTRUCTORS
  284.     TGXApplication();
  285.     virtual~ TGXApplication();
  286. };
  287.  
  288.  
  289. // _________________________________________________________________________________________________________ //
  290. //    TQTAndGXApplication Interface.
  291.  
  292. class TQTAndGXApplication : public TGUIApplication
  293. // The TGXApplication is the base class for writing window/menu based user interaction applications
  294. // that handles both Quickdraw GX and QuickTime calls.
  295. {
  296. public:
  297.     // CONSTRUCTORS AND DESTRUCTORS
  298.     TQTAndGXApplication();
  299.     virtual~ TQTAndGXApplication();
  300. };
  301.  
  302.  
  303. #endif
  304.  
  305. // _________________________________________________________________________________________________________ //
  306.  
  307.  
  308. /*    Change History (most recent last):
  309.   No        Init.    Date        Comment
  310.   1            khs        11/6/92        New file
  311.   2            khs        1/14/92        Cleanup
  312. */
  313.